	#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include "memPool_t.h"

typedef int type;

typedef struct{
	int  num;
	char val;
}check;

int RandomInt(int from , int to) {              // return random integer between [from-to] 
	  int rnd = from + rand()%(to-from+1);
	  return rnd;
}

int main(void) 
{
	srand(time(NULL));
	memPool_t pool(1);

	int iter = 0;
	for (;iter < 3;iter++)
	{	
	
		cout<<"This is writing iteration #"<<iter + 1<<endl;
		
		for (int i = 0; i<50;i++)
		{
			pool.write<type>(i + 50*iter,sizeof(type));
		}
		
		cout<<"After "<<iter<<" iteration the pool status is:"<<endl<<endl;
		cout<<"The Pool capacity is: "<<pool.getCapacity()<<endl;
		cout<<"The pool used space is: "<<pool.getUsedSpace()<<endl;
		cout<<"Page size:"<<pool.getDefaultPageSize()<<endl;
		cout<<"Number Of pages is: "<<pool.getNumOfPages()<<endl<<endl<<endl;
		pool.setDefaultPageSize(RandomInt(1,15));
	}
	
	int randPlace = 0;
	int shifting = 0;
	type val;
	
		for (int i = 0; i < 50*iter;i++)
	{
		randPlace = RandomInt(0,pool.getUsedSpace() - sizeof(type));
		shifting  = randPlace % (sizeof(type));
		if (shifting != 0)
			randPlace -= shifting;
		pool.setPosition(randPlace);
		pool.read<type>(val,sizeof(type));
		cout<<"The number in index:"<<(randPlace / sizeof(val))<<"\tis "<<val<<endl;	
	}
	
	
	
}